﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System;
using System.Data.SqlClient;
using System.Data;
/// <summary>
/// Summary description for Certificate
/// </summary>
public class Certificate
{
	public Certificate()
	{
		
	}

    string policyNo { set; get; }
    int applicationId { set; get; }
    DateTime? issueDate { set; get; }
    string benefitType { set; get; }
    string staffId { set; get; }
    decimal minBalance { set; get; }


    public string create(Application application)
    {
        string sql = "INSERT R_POLICY (POLICY_NO,APPLICATION_ID, ISSUE_DATE, BENEFIT_TYPE, STAFF_ID, MIN_BALANCE)" +
                      "VALUES ( " +
                      "@POLICY_NO," +
                      "@APPLICATION_ID," +
                      "@ISSUE_DATE," +
                      "@BENEFIT_TYPE," +
                      "@STAFF_ID," +
                      "@MIN_BALANCE" +
                      ")";

        SqlConnection conn = DBManager.getSqlConnection();
        conn.Open();
        var cmd = new SqlCommand(sql, conn);
        string policyNo = new AccountsManager().GenerateNo("POLICY");
        cmd.Parameters.Add(new SqlParameter("@POLICY_NO", (object)policyNo ?? DBNull.Value));
        cmd.Parameters.Add(new SqlParameter("@APPLICATION_ID", (object) application.applicationId??DBNull.Value));
        cmd.Parameters.Add(new SqlParameter("@ISSUE_DATE", (object)issueDate ?? DBNull.Value));
        cmd.Parameters.Add(new SqlParameter("@BENEFIT_TYPE", (object)benefitType ?? DBNull.Value));
        cmd.Parameters.Add(new SqlParameter("@STAFF_ID", (object)staffId ?? DBNull.Value));
        cmd.Parameters.Add(new SqlParameter("@MIN_BALANCE", (object)minBalance ?? DBNull.Value));

        cmd.ExecuteNonQuery();
        conn.Close();

        Console.WriteLine();
        /*  sql = "SELECT [policy_no]"
                  + ",[application_id]"
                  + ",[issue_date]"
                  + ",[benefit_type]"
                  + ",[staff_id]"
                  + ",[min_balance]"
                  + "FROM [R_POLICY] where policy_no=@policyNo";

          cmd = new SqlCommand(sql, conn);
          cmd.Parameters.AddWithValue("@policyNo", policyNo);
        
          SqlDataAdapter myAdapter = new SqlDataAdapter(cmd);

          DataSet myDs = new DataSet();
          myAdapter.Fill(myDs, "IllnessList");
          */
        return policyNo;

    }
}